package com.syyo.common.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

/**
 * @ author: wang
 * @ date: 2021/4/21 9:34
 * @ Description:  json 类型转换
 */
public class MyJSONUtils {

    //利用fastjson进行反序列化，转成对应的类型
    public static <T> T typeCast(TypeReference<T> typeReference, Object data) {
        if (data == null) {
            return null;
        }
        String jsonString = JSON.toJSONString(data);
        T t = JSON.parseObject(jsonString, typeReference);
        return t;
    }
}
